﻿using System;
using System.Drawing;
using System.Windows.Forms;
using ClientApp.Gestori;
using GianosNET.Common.Classes;


namespace ClientApp.UC
{
    public partial class NavItem : UserControl
    {
        private ContextMenuStrip ctxSystem;
        private ToolStripMenuItem TSMIStart;
        private ToolStripMenuItem TSMIStop;
        private ToolStripMenuItem TSMIRestart;

        public Base Gestore { get; private set; }

       

        public NavItem(string header, string info, Gestori.Base gestore, string instanceName = null)
        {
            InitializeComponent();

            SetMainTitle(string.Format("{0}{1}{2}{3}", 
                header,
                Environment.NewLine, 
                info,
                !string.IsNullOrEmpty(instanceName)
                    ? string.Format(" ({0})", instanceName)
                    : ""));

            Gestore = gestore;
        }

        public void SetMainTitle(string txt)
        {
            lblMain.Text = txt;
        }

        public void SetBottomTitle(string txt)
        {
            lblBottom.Text = txt;
        }

        public void SetStatus(RemotedClass.RemotedClassStatusEnum status)
        {
            this.BackColor =
                status == RemotedClass.RemotedClassStatusEnum.Started
                                  ? Color.Green
                                  : (status == RemotedClass.RemotedClassStatusEnum.Stopped
                                         ? Color.Red
                                         : Color.DarkOrange);
        }

        public void SetBorderColor(Color c)
        {
            //this.BorderColor = c;
        }

        #region ctxSystem

        private void TSMIStart_Click(object sender, EventArgs e)
        {
            Gestore.StartService();
        }

        private void TSMIStop_Click(object sender, EventArgs e)
        {
            Gestore.StopService();
        }

        private void TSMIRestart_Click(object sender, EventArgs e)
        {
            //obj.Restart();
        }

        #endregion

        public void OpenMenu(NavItem cTile, Point location)
        {
            ctxSystem.Show(cTile, location);
        }

        private void lblMain_MouseDown(object sender, MouseEventArgs e)
        {
            Control c = sender as Control;
            this.OnMouseDown(new MouseEventArgs(e.Button, e.Clicks, c.Left + e.X, c.Top + e.Y, e.Delta));
        }

    }
}
